package com.zeroes.cons;


import org.zeroes.common_prelude.*;
import org.zeroes.common_prelude.Font.Style;
import org.zeroes.common_prelude.TextFormat.Alignment;
import org.zeroes.common_prelude.TextFormat.Effect;

import android.graphics.Color;

public class ZSLabel extends ZSSprite{

	public ZSLabel(String text ,Style style, float size, int color,float wrapwidth){
		
		super();
		
		setup(text,style,size,color,wrapwidth);
		
	}
	
	public ZSLabel(String text ,String style, float size, int[] color,float wrapwidth){
		
		super();
		Style _style=null;
		if(style.equals("PLAIN"))
			_style=Style.PLAIN;
		if(style.equals("ITALIC"))
			_style=Style.ITALIC;
		if(style.equals("BOLD"))
			_style=Style.BOLD;
		if(style.equals("BOLD_ITALIC"))
			_style=Style.BOLD_ITALIC;
		
		int clr = Color.argb(color[0], color[1], color[2], color[3]);
		setup(text,_style,size,clr,wrapwidth);
		
	}
	private void setup(String text ,Style style, float size, int color,float wrapwidth){
		
		aTex = new ZSTexture2D();
		this.clr=color;
		this.ww=wrapwidth;
		this.tstyle=style;
		this.text=text;
		this.sz=size;
		AndroidFont af= new AndroidFont(null,style,size);
		TextFormat textFormat=new TextFormat(af,wrapwidth,Alignment.LEFT, color, Effect.NONE);
		aTex.drawFormatedText(text, textFormat);
		newTexture(aTex);
	}
	public boolean textureDirty=false;
	private ZSTexture2D aTex;
	private Style tstyle;
	private float sz=0;
	private float ww=0;
	private int clr;
	private String text;
	public void visitLocal(float a ){
		super.visitLocal(a);
		if(!textureDirty)
			return;
		
		
		AndroidFont af= new AndroidFont(null,tstyle,sz);
		
		TextFormat tf = new TextFormat(af,ww,Alignment.LEFT, clr, Effect.NONE);
		this.aTex.drawFormatedText(text, tf);

		newTexture(aTex);
		textureDirty=false;
	}
	public void newText(String newtext){
		
		text=newtext;
		visit();
	}
	public void newStyle(Style newstyle){
		
		this.tstyle=newstyle;
		visit();
	}
	public void newSize(float newsize){
		
		this.sz=newsize;
		visit();
	}
	/**
	 * 
	 * @param aColor
	 */
	public void newColor(int aColor){
		
		this.clr=aColor;
		visit();
	}
	public void newWidthWrap(float wrap){
		this.ww=wrap;
		visit();
	}
	
	public void visit(){
		this.textureDirty=true;
	}
	
	public String getText(){
		
		return this.text;
	}
	public Style getStyle(){
		
		return this.tstyle;
	}
	public int getColor(){
		return this.clr;
	}
	public float getWidthWrap(){
		return this.ww;
	}

	
}
